//
//  BaseTabBarController.m
//  Connections
//
//  Created by beisheng03 on 2017/9/28.
//  Copyright © 2017年 beisheng. All rights reserved.
////

#import "BaseTabBarController.h"
#import "BaseNavigationController.h"
#import "HomeViewController.h"
#import "MeViewController.h"
#import "ShopCarController.h"
#import "CommunityController.h"
#import "MarketController.h"
#import "LoginViewController.h"
#import "WineCategoryVC.h"

#import "AboutusController.h"
@interface BaseTabBarController ()

@end

@implementation BaseTabBarController


// 加载类进内存的时候调用,只会调用一次
+ (void)load
{
    // 获取当前类下所有的tabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    // 设置选中标题的颜色
    // 创建富文本属性字典
    NSMutableDictionary *testAttr = [NSMutableDictionary dictionary];
    
    // 描述颜色
    testAttr[NSForegroundColorAttributeName] = themeColor;
    
    // 设置标题的富文本属性
    [item setTitleTextAttributes:testAttr forState:UIControlStateSelected];
    
    // 问题:设置字体颜色不好使,注意:一定要先设置正常状态下字体大小
    // 设置正常状态下字体
    NSMutableDictionary *testAttrNor = [NSMutableDictionary dictionary];
    
    // 描述字体
    testAttrNor[NSFontAttributeName] = MYFONT(13);
    
    // 设置标题的富文本属性
    [item setTitleTextAttributes:testAttrNor forState:UIControlStateNormal];
}






- (void)viewDidLoad {
    [super viewDidLoad];
    // 1 添加UITabBarController子控制器
    [self setupAllChildViewController];
    
    // 2 设置tabBar上所有按钮内容
    [self setupAllTabBarButton];
    
    
    
}


- (void)login{
    
    BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:[[LoginViewController alloc]init]];
    
    [self presentViewController:nav animated:YES completion:nil];
}



#pragma mark - 添加所有的子控制器
- (void)setupAllChildViewController
{
    
    
    if (myViewModel.hideShopping) {
        
        
        HomeViewController *homeVC = [[HomeViewController alloc] init];
        homeVC.navigationItem.title = @"菲度";
        BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:homeVC];
        [self addChildViewController:nav];
        
     
        AboutusController *marketVc = [[AboutusController alloc] init];
        marketVc.navigationItem.title = @"客服";
        marketVc.type = @"kefu";
        BaseNavigationController *nav1 = [[BaseNavigationController alloc] initWithRootViewController:marketVc];
        [self addChildViewController:nav1];
        
        
        MeViewController *meVc = [[MeViewController alloc] init];
        meVc.navigationItem.title = @"我";
        BaseNavigationController *nav4 = [[BaseNavigationController alloc] initWithRootViewController:meVc];
        [self addChildViewController:nav4];
        
    } else {
        
        HomeViewController *homeVC = [[HomeViewController alloc] init];
        homeVC.navigationItem.title = @"菲度";
        BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:homeVC];
        [self addChildViewController:nav];
        
        
        
        
        WineCategoryVC *marketVc = [[WineCategoryVC alloc] init];
        marketVc.navigationItem.title = @"商城";
        marketVc.type = @"wine";
        marketVc.seletIndex = 0;
        BaseNavigationController *nav1 = [[BaseNavigationController alloc] initWithRootViewController:marketVc];
        [self addChildViewController:nav1];
        
        
        //    CommunityController *communityVc = [[CommunityController alloc] init];
        //    communityVc.navigationItem.title = @"社区";
        //    BaseNavigationController *nav2 = [[BaseNavigationController alloc] initWithRootViewController:communityVc];
        //    [self addChildViewController:nav2];
        
        
        //
        //    ShopCarController *shopCarVc = [[ShopCarController alloc] init];
        //    shopCarVc.navigationItem.title = @"购物车";
        //    BaseNavigationController *nav3 = [[BaseNavigationController alloc] initWithRootViewController:shopCarVc];
        //    [self addChildViewController:nav3];
        
        
        
        
        MeViewController *meVc = [[MeViewController alloc] init];
        meVc.navigationItem.title = @"我";
        BaseNavigationController *nav4 = [[BaseNavigationController alloc] initWithRootViewController:meVc];
        [self addChildViewController:nav4];
        
    }


    
    
    
    // Storyboard必须手动加载 1.加载Storyboard文件 2.加载箭头指向控制器
    // 加载Storyboard文件
//    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:NSStringFromClass([XMGMeViewController class]) bundle:nil];
//
//    // instantiateInitialViewController:加载箭头指向控制器
//    XMGMeViewController *meVc = [storyboard instantiateInitialViewController];
//
//    XMGNavigationController *nav4 = [[XMGNavigationController alloc] initWithRootViewController:meVc];
//    // initWithRootViewController -> push
//    [self addChildViewController:nav4];
    
}



#pragma mark - 设置所有的TabBarButton
- (void)setupAllTabBarButton
{
    
    
    if (myViewModel.hideShopping) {
        //精华按钮 0个子控制器
        UINavigationController *nav = self.childViewControllers[0];
        nav.tabBarItem.title = @"首页";
        nav.tabBarItem.image = [UIImage imageNamed:@"tabbarNormalAN"];
        nav.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbarSelectAL"];
        
        UINavigationController *nav1 = self.childViewControllers[1];
        nav1.tabBarItem.title = @"客服";
        nav1.tabBarItem.image = [UIImage imageNamed:@"tabbarNormalBN"];
        nav1.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbarSelectBL"];
     
        UINavigationController *nav4 = self.childViewControllers[2];
        nav4.tabBarItem.title = @"个人中心";
        nav4.tabBarItem.image = [UIImage imageNamed:@"tabbarNormalCN"];
        nav4.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbarSelectCL"];
        
        
    } else {
        //精华按钮 0个子控制器
        UINavigationController *nav = self.childViewControllers[0];
        nav.tabBarItem.title = @"首页";
        nav.tabBarItem.image = [UIImage imageNamed:@"tabbarNormalAN"];
        nav.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbarSelectAL"];
        
        
        UINavigationController *nav1 = self.childViewControllers[1];
        nav1.tabBarItem.title = @"商城";
        nav1.tabBarItem.image = [UIImage imageNamed:@"tabbarNormalBN"];
        nav1.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbarSelectBL"];
        
        //    UINavigationController *nav2 = self.childViewControllers[2];
        //    nav2.tabBarItem.title = @"社区";
        //    nav2.tabBarItem.image = [UIImage imageNamed:@"tabbar_mainframe"];
        //    nav2.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_mainframeHL"];
        
        //关注按钮 2
        //    UINavigationController *nav3 = self.childViewControllers[2];
        //    nav3.tabBarItem.title = @"购物车";
        //    nav3.tabBarItem.image = [UIImage imageNamed:@"tabbarNormal001"];
        //    nav3.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbarSelect001"];
        
        UINavigationController *nav4 = self.childViewControllers[2];
        nav4.tabBarItem.title = @"个人中心";
        nav4.tabBarItem.image = [UIImage imageNamed:@"tabbarNormalCN"];
        nav4.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbarSelectCL"];
        
    }
   
    
   
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
